home *** CD-ROM | disk | FTP | other *** search
/ ASP Advantage 1994 2nd Q2 / The Association of Shareware Professionals - The Official ASP Advantage (2nd Quarter)(1994).bin / files / progming / kfs / kfs.doc < prev    next >
Encoding:
Text File  |  1994-02-15  |  67.8 KB  |  2,646 lines

  1.          
  2.  
  3.  
  4.  
  5.  
  6.  
  7.          
  8.          
  9.          
  10.          
  11.          
  12.          
  13.          
  14.          
  15.          
  16.          
  17.          
  18.          
  19.          
  20.                          KEYED FILE SYSTEM - User's Guide
  21.          
  22.                           Version 2.0 (DOS and OS/2 1.x)
  23.          
  24.          
  25.                        (c) 1993 APT Computer Solutions, Inc.
  26.          
  27.          
  28.          
  29.          
  30.  
  31.          
  32.  
  33.  
  34.  
  35.  
  36.  
  37.                                          Table of Contents
  38.          
  39.          Introduction  1
  40.          
  41.          System Components and Requirements  2
  42.          System Requirements  2
  43.          Keyed File System Components  2
  44.          Keyed File System Restrictions  2
  45.          
  46.          Including KFS Routines in Your Program  4
  47.          
  48.          What Are Keyed Files  5
  49.          
  50.          Keyed File System Functions  7
  51.          
  52.          The File Information Structure  8
  53.          
  54.          Parameters to Keyed File System Functions 10
  55.          
  56.          Keyed File System Functions 11
  57.          KFS_Add 11
  58.          KFS_Close 13
  59.          KFS_Create 14
  60.          KFS_Delete 16
  61.          KFS_Open 18
  62.          KFS_Read 19
  63.          KFS_ReadFirst 20
  64.          KFS_ReadGen 21
  65.          KFS_ReadGenNumeric 23
  66.          KFS_ReadNext 25
  67.          KFS_Replace 27
  68.          Interdependencies of the KFS operations 29
  69.          
  70.          Special Processing 30
  71.          KFS_Small_PTR 30
  72.          KFS_Numeric_Key 30
  73.          KFS_Ignore_Case 31
  74.          
  75.          Programming Hints and Tips 32
  76.          
  77.          Data Recovery 34
  78.          
  79.          Appendix A - Keyed File System Return Codes 35
  80.          
  81.          Appendix B - File Recovery Example 37
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.                                  3
  97.  
  98.          
  99.          
  100.          
  101.          
  102.          
  103.  
  104.  
  105.  
  106.  
  107.  
  108.          Introduction
  109.          
  110.          The Keyed File System is a set of routines that allow you to 
  111.          write programs in C to build and maintain databases on a PC that 
  112.          are logically organized by a user defined key. Records can be 
  113.          read or written directly using an alphabetic or numeric key. An 
  114.          alphabetic key can be a string consisting of any combination of 
  115.          ASCII characters up to 32,767 characters in length. You may also 
  116.          have 4 byte signed numeric keys contained in the normal Intel 
  117.          80x86 long integer format. Note that a database may have alpha-
  118.          betic keys or numeric keys but not both (however, see 
  119.          "Programming Hints & Tips" for hints about combining keys).
  120.          
  121.          The Keyed File System uses normal DOS and OS/2 functions to 
  122.          create and maintain its databases. Therefore, records may be of 
  123.          any length supported by the DOS or OS/2 operating systems and 
  124.          can be created using the FAT or HPFS (OS/2 only) file systems. 
  125.          Files may be created on floppy or hard disks, although, as might 
  126.          be expected, hard disk files will provide better performance. 
  127.          KFS databases may be moved or copied using normal DOS or OS/2 
  128.          commands (such as COPY) as long as both file components are 
  129.          moved together (see "Copying Files"). Additionally, databases 
  130.          built using the KFS functions on one operating system are com-
  131.          patible with databases built using the KFS functions on the 
  132.          other operating system. Thus, databases built by programs run-
  133.          ning under DOS may be subsequently used by programs running 
  134.          under OS/2.
  135.          
  136.          The Keyed File System supports most operations normally associ-
  137.          ated with keyed files:
  138.          
  139.          *    Direct reading and writing of records by key.
  140.          
  141.          *    Sequential reading of records in key sequence.
  142.          
  143.          *    Deleting of records by key.
  144.          
  145.          *    Reading records using a partial key.
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.                                  4
  168.  
  169.          
  170.          
  171.          
  172.          
  173.          
  174.  
  175.  
  176.  
  177.  
  178.  
  179.          System Components and Requirements
  180.          
  181.          System Requirements
  182.          
  183.               The minimum system required to run programs that use the 
  184.          Keyed File System are:
  185.          
  186.          *    OS/2 1.2 or higher, or DOS 3.3 or higher.
  187.          
  188.          *    Approx. 180K of disk space including sample programs and 
  189.               utilities.
  190.               
  191.          *    Microsoft C compiler and libraries, version 6.0 (OS/2 and 
  192.               DOS) or 7.0 (DOS only).
  193.          
  194.          
  195.          Keyed File System Components
  196.          
  197.          KFS.H             - The header file for use in C programs that 
  198.                              want to use KFS functions.
  199.          
  200.          KFSMSC6O.LIB      - A lib used at linkedit time to include the 
  201.                              KFS functions when building OS/2 programs 
  202.                              written in Microsoft C Version 6.0.
  203.          
  204.          KFSMSC6D.LIB      - A lib used at linkedit time to include the 
  205.                              KFS functions when building DOS programs 
  206.                              written in Microsoft C Version 6.0.
  207.          
  208.          KFSMSC7.LIB       - A lib used at linkedit time to include the 
  209.                              KFS functions when building DOS programs 
  210.                              written in Microsoft C Version 7.0.
  211.          
  212.          KFSSAMP.C         - A sample program that builds a KFS database 
  213.                              from a sequential file and then uses most of 
  214.                              the functions available in KFS. 
  215.          
  216.          KFSSAMP.DAT       - The sequential input file to the KFSSAMP 
  217.                              program.
  218.          
  219.          KFSSAMP.MAK       - A sample make file for KFSSAMP.C. 
  220.          
  221.          
  222.          Keyed File System Restrictions
  223.          
  224.          The following restrictions apply to KFS databases:
  225.          
  226.          *    Databases must contain fixed length records.
  227.          
  228.          *    Each record must be at least 5 bytes in length.
  229.          
  230.          *    Numeric keys must be 4 bytes in length but alphabetic keys 
  231.               may be up to 32767 characters in length.
  232.          
  233.          *    Duplicate keys are not allowed (see "Programming Tips and 
  234.               Techniques").
  235.          
  236.          *    The path and file name specified during KFS_Create or 
  237.               KFS_Open for a KFS database cannot be longer than 63 bytes.
  238.          
  239.                                  5
  240.  
  241.          
  242.          
  243.          
  244.          
  245.          
  246.  
  247.  
  248.  
  249.  
  250.  
  251.          *    Files cannot be created using KFS_Open, you must use 
  252.               KFS_Create to create a new file and KFS_Open after a file 
  253.               exists.
  254.          
  255.          *    Two databases with the same "base" name cannot exist in the 
  256.               same directory even if the file extensions are different. 
  257.               That is KFS databases with the base names of MYFILE.001 and 
  258.               MYFILE.002 cannot exist in the same directory, but the 
  259.               names MYFILE1.XXX and MYFILE2.XXX are OK. This is explained 
  260.               further in the section "What Are Keyed Files".
  261.          
  262.          *    You cannot name a KFS database using the extension of .PTR. 
  263.               Thus MYFILE.PTR is invalid. This is also explained in the 
  264.               "What Are Keyed Files" section.
  265.  
  266.          
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.                                  6
  312.  
  313.          
  314.          
  315.          
  316.          
  317.          
  318.  
  319.  
  320.  
  321.  
  322.  
  323.          Including KFS Routines in Your Program
  324.          
  325.          To include the KFS routines in your C program requires three 
  326.          steps:
  327.          
  328.          1.   Include the KFS.H header file at the beginning of your 
  329.               program source. For example:
  330.                    #include <KFS.H>
  331.          
  332.          2.   Define any keyed files using the KFS_FILEINFO typedef. For 
  333.               example:
  334.                    KFS_FILEINFO keyedfile;
  335.          
  336.          3.   Include the appropriate KFS---.LIB file when linking your 
  337.               program. For example, to link a DOS program compiled with 
  338.               MS/C version 6.0 would be:
  339.                    LINK myprog,,,KFSMSC6D;
  340.          
  341.          For a complete example of a program using some KFS functions, 
  342.          look at the KFSSAMP.C file included with this package.
  343.          
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.                                  7
  384.  
  385.          
  386.          
  387.          
  388.          
  389.          
  390.  
  391.  
  392.  
  393.  
  394.  
  395.          What Are Keyed Files
  396.          
  397.          Keyed File System databases are actually composed of two files, 
  398.          an index file and a data file. These two files work together to 
  399.          provide you with direct access of a record by key while keeping 
  400.          the records in a logical keyed sequence. The name of the data 
  401.          file is the same as the name of the database and is specified by 
  402.          the programmer when the KFS database is created (using the 
  403.          KFS_Create function). This may be any valid DOS or OS/2 file 
  404.          name. The index file is automatically given the same base name 
  405.          you specified for the database but with an extension of .PTR. 
  406.          For example, specifying a name of CUSTOMER.DAT for a database 
  407.          automatically causes the creation of an index file with the name 
  408.          of CUSTOMER.PTR. This leads to two restrictions in the Keyed 
  409.          File System:
  410.          
  411.          1)   You cannot name a database using an extension of .PTR.
  412.          
  413.          2)   You cannot have two databases in the same directory with 
  414.               the same base name since this would result in an attempt by 
  415.               KFS to create duplicate .PTR files. For example, MYFILE.001 
  416.               and MYFILE.002 would both result in KFS attempting to cre-
  417.               ate an index file named MYFILE.PTR.
  418.          
  419.          Because these two files work together they must remain physi-
  420.          cally in the same directory. Therefore, if the Keyed File System 
  421.          database is moved, both the data and index files must be moved 
  422.          together.
  423.          
  424.          The format and content of the index file is determined by the 
  425.          Keyed File System, while the format and content of the data file 
  426.          is determined by you when the database is created. When you 
  427.          create a Keyed File System database you must tell the Keyed File 
  428.          System how large each record in the database will be 
  429.          (KFS_recsize), where the key begins in the record (KFS_keypos), 
  430.          and how long the key is (KFS_keylen). Note that the Keyed File 
  431.          System only supports fixed length records (ie. each record in 
  432.          the database is the same length).
  433.          
  434.          The Keyed File System requires that databases are either created 
  435.          or opened before they are used, and that they are closed before 
  436.          the program terminates. With any file system, if a program ter-
  437.          minates abnormally without closing files (such as a system crash 
  438.          because of a power failure) and file buffering is being used 
  439.          (such as is available with HPFS or DOS lazy writing), data that 
  440.          has been "written" by the program but waiting in an output 
  441.          buffer to be physically written to disk may be lost. The Keyed 
  442.          File System makes every attempt to minimize the impact of such a 
  443.          system failure, but since it does utilize two files working 
  444.          together, there are rare times this loss of data may result in 
  445.          the database becoming unusable. Thus special care should be 
  446.          taken by your application user to properly back up the data and 
  447.          index files making up each KFS database. Also, see the section 
  448.          on "Data Recovery" for an example of how to recover a damaged 
  449.          KFS database.
  450.          
  451.  
  452.  
  453.  
  454.  
  455.                                  8
  456.  
  457.          
  458.          
  459.          
  460.          
  461.          
  462.  
  463.  
  464.  
  465.  
  466.  
  467.          Keyed File System Functions
  468.          
  469.          The Keyed File System is a set of 11 routines that provide you 
  470.          with the basic functions required for keyed record access on the 
  471.          PC. These functions are:
  472.          
  473.          KFS_Add
  474.               Adds a new record to a KFS database. The key of the record 
  475.               being added must not already exist in the database.
  476.          
  477.          KFS_Close
  478.               Close an open KFS database.
  479.          
  480.          KFS_Create 
  481.               Create and open a new KFS database. The database must not 
  482.               already exist.
  483.          
  484.          KFS_Delete
  485.               Deletes the record from a KFS database that has the key 
  486.               specified.
  487.          
  488.          KFS_Open
  489.               Open an existing KFS database.
  490.          
  491.          KFS_Read
  492.               Read a record from an open KFS database by key.
  493.          
  494.          KFS_ReadFirst
  495.               Reads the first logical record in a KFS database.
  496.          
  497.          KFS_ReadGen
  498.               For databases with alphabetic keys only. Read a record from 
  499.               an open KFS database using a partial key. If no records 
  500.               match the partial key, the next record in sequence after 
  501.               the key requested is returned in the user area and a code 
  502.               of KFS_Key_Not_Found is returned in KFS_rc.
  503.          
  504.          KFS_ReadGenNumeric 
  505.               For databases with numeric keys only. Read a record from an 
  506.               open KFS database. If the requested key is not found, the 
  507.               next record in sequence after the key requested is returned 
  508.               in the user area and a return code of KFS_Key_Not_Found is 
  509.               returned in KFS_rc.
  510.          
  511.          KFS_ReadNext
  512.               Reads the record in a KFS database that is the next record 
  513.               after the key specified.
  514.          
  515.          KFS_Replace
  516.               Replaces the record in a KFS database that has the same key 
  517.               as the one specified. A record with this key must exist in 
  518.               the database.
  519.          
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.                                  9
  528.  
  529.          
  530.          
  531.          
  532.          
  533.          
  534.  
  535.  
  536.  
  537.  
  538.  
  539.          The File Information Structure
  540.          
  541.          In order to use the Keyed File System routines, you must provide 
  542.          the KFS functions with a File Information Structure for each 
  543.          database you are going to use in your program. This is a control 
  544.          structure (similar to the C "FILE" typedef) that includes such 
  545.          information about the database as the database name, key length, 
  546.          location of the key within the record, and a return code field 
  547.          for checking the result of KFS operations, as well as control 
  548.          fields used by the KFS functions themselves. Once the database 
  549.          is opened, this structure should not be modified by the appli-
  550.          cation since this may damage the control information used by the 
  551.          KFS functions and the integrity of the database may be compro-
  552.          mised. There is a C typedef named KFS_FILEINFO for this 
  553.          structure defined in the KFS.H header file provided with the 
  554.          system. Also present in this header file are the C prototypes 
  555.          for the KFS functions and the definitions of the KFS return 
  556.          codes. 
  557.          
  558.          To create a KFS database (using the KFS_Create operation), you 
  559.          must provide several important pieces of information about the 
  560.          database. This is done by placing the appropriate values in the 
  561.          following fields in the File Information Structure defined for 
  562.          the file:
  563.          
  564.               KFS_filename
  565.                    Required for KFS_Create or KFS_Open, this field must 
  566.                    contain the name of the database being created or 
  567.                    opened. This is a DOS or OS/2 file specification that 
  568.                    includes drive, path, and database name. As mentioned 
  569.                    before the Keyed File System actually creates (or 
  570.                    opens) two files for any KFS database and if these 
  571.                    files are moved, both must be move to the same loca-
  572.                    tion (ie. subdirectory or floppy disk). The first file 
  573.                    will have the name you specify here, while the second 
  574.                    file will have the same base name as the database you 
  575.                    specified but a qualifier of .PTR.    
  576.          
  577.               KFS_keypos
  578.                    KFS_Create only. This is the position of the key 
  579.                    within the record. This position is relative to 0. 
  580.                    That is, if the key begins in the first position of 
  581.                    the record, 0 is placed here by the programmer. If the 
  582.                    key begins in the 5th position of the record, 4 is put 
  583.                    here. 
  584.          
  585.               KFS_keylen
  586.                    KFS_Create only. This is the length of the key in the 
  587.                    record. For example, if the key went from position 5 
  588.                    through position 10 (ie. 6 characters long) in the 
  589.                    data record, 6 would be placed here. For numeric keys, 
  590.                    this field is ignored.
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.                                 10
  599.  
  600.          
  601.          
  602.          
  603.          
  604.          
  605.  
  606.  
  607.  
  608.  
  609.  
  610.               KFS_recsize
  611.                    KFS_Create only. Place the total size of each data 
  612.                    record, including the key in this field. 
  613.          
  614.               KFS_flags
  615.                    KFS_Create only. These flags specify any special pro-
  616.                    cessing required for the database. The options 
  617.                    available to you are normal pointer file, small 
  618.                    pointer file, numeric keys, and ignore case. These 
  619.                    options are discussed further in the section  "Special
  620.                    Processing".   
  621.          
  622.          Once a KFS database is created, it may be subsequently used by 
  623.          simply specifying the name of the database in the KFS_filename 
  624.          field of the File Information structure and using KFS_Open to 
  625.          open the database. The remaining information about the database 
  626.          (ie. KFS_keypos, KFS_keylen, KFS_recsize, and KFS_flags) is 
  627.          stored with the database when it is created. 
  628.          
  629.          Upon the completion of a KFS operation, the success or failure 
  630.          of the operation is determined by checking the return code pro-
  631.          vided in the database's KFS_FILEINFO field KFS_rc. The valid 
  632.          return codes are defined in the KFS.H header file and are docu-
  633.          mented in Appendix A of this User's Guide.
  634.          
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668.  
  669.  
  670.                                 11
  671.  
  672.          
  673.          
  674.          
  675.          
  676.          
  677.  
  678.  
  679.  
  680.  
  681.  
  682.          Parameters to Keyed File System Functions
  683.          
  684.          The are 11 application interfaces that can be called to perform 
  685.          operations on databases with the Keyed File System. These 
  686.          operations require 1, 2, or 3 parameters depending on the func-
  687.          tion desired.
  688.          
  689.          The first parameter to all of the KFS functions is always the 
  690.          address of the KFS File Information structure (KFS_FILEINFO) for 
  691.          the desired database. As mentioned before, once a database is 
  692.          created or opened this structure should not be changed by the 
  693.          programmer since it is used by the database system to keep track 
  694.          of current information about the database. It is also used to 
  695.          provide feedback to the programmer about the requested opera-
  696.          tion.
  697.          
  698.          The second parameter is necessary for the functions that will be 
  699.          reading data from or writing data to a KFS database. This 
  700.          parameter is the address of an area large enough to contain a 
  701.          record from the database (that is, at least KFS_recsize in 
  702.          length). When a key is required by a specific KFS operation, the 
  703.          system expects the key to be in this area at the same relative 
  704.          position, and with the same length, as the key in a record in 
  705.          the database. For example, to read a record with the key "ABCDE" 
  706.          for a database whose KFS_keypos = 3, KFS_keylen = 5, and 
  707.          KFS_recsize = 80 means that the second parameter would be the 
  708.          address of an area at least 80 bytes in length that contains 
  709.          "ABCDE" in the 4th, 5th, 6th, 7th, and 8th bytes (ie. 
  710.          ...ABCDE..). 
  711.          
  712.          The third parameter is only required on the KFS_ReadGen function 
  713.          and is the length of the portion of the key provided. This 
  714.          parameter is discussed further in the discussion of KFS_ReadGen. 
  715.          The following program segment illustrates how the above param-
  716.          eters would be specified for a typical KFS function call:
  717.          
  718.            #include <kfs.h>
  719.            KFS_FILEINFO file1;
  720.            char recarea[100];
  721.          
  722.            strcpy(file1.KFS_filename, "C:\\MYDIR\\MYFILE.DAT");
  723.            KFS_Open(&file1);
  724.            if (file1.KFS_rc != KFS_OK)
  725.               printf("Error opening file1\n");
  726.            strcpy(&recarea[file1.KFS_keypos], "A k");
  727.            KFS_ReadGen(&file1, (void *)recarea, 3);
  728.          
  729.          For further examples, see the description of the individual KFS 
  730.          functions and the KFSSAMP.C program provided as part of this 
  731.          package.
  732.          
  733.  
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740.  
  741.  
  742.                                 12
  743.  
  744.          
  745.          
  746.          
  747.          
  748.          
  749.  
  750.  
  751.  
  752.  
  753.  
  754.          Keyed File System Functions
  755.          
  756.          In the description of the following functions the KFS_File_Error 
  757.          is a general error caused by an "unknown error" returned from 
  758.          the operating system and is possible for all functions.
  759.          
  760.          KFS_Add(fs, area)
  761.               Add a data record to a database. 
  762.          
  763.          Parameters
  764.               KFS_FILEINFO *fs
  765.                    A pointer to a KFS file structure.
  766.          
  767.               void *area
  768.                    A pointer to a data area containing the record to be 
  769.                    added. The key to be added must be at KFS_keypos of 
  770.                    this area before the operation is issued.
  771.           
  772.          
  773.          
  774.          Description
  775.               Add a record to the database. Another record with this key 
  776.               must not already exist in the database.
  777.          
  778.          
  779.          Required Fields
  780.               KFS_filename
  781.                    Contains the name of an open database where the record 
  782.                    is to be added.
  783.          
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.  
  801.  
  802.  
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813.  
  814.                                 13
  815.  
  816.          
  817.          
  818.          
  819.          
  820.          
  821.  
  822.  
  823.  
  824.  
  825.  
  826.          Example
  827.            /* Add a record to a KFS file                              */
  828.            #include <kfs.h>
  829.            KFS_FILEINFO file1;
  830.            typedef struct m {
  831.               int f1;
  832.               int f2;
  833.               char mykey[7];
  834.               char filler[89];
  835.            } MYSTRUCT;
  836.            MYSTRUCT inarea;
  837.          
  838.            strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
  839.            KFS_Open(&file1);
  840.            if (file1.KFS_rc != KFS_OK)
  841.               printf("Error opening file1\n");
  842.            strcpy(&inarea.mykey, "Newkey");
  843.            inarea.f1 = 0;    /* Just some data in record */ 
  844.            inarea.f2 = 15;   /* Just some data in record */
  845.            KFS_Add(&file1, (void *)&inarea);
  846.            switch (file1.KFS_rc) {
  847.               case KFS_Key_Already_Exists :
  848.                  printf("Key already in file");
  849.               case KFS_OK:
  850.                  break;
  851.               default:
  852.                  printf("Error adding record");
  853.            }
  854.          
  855.          
  856.          Possible KFS_rc Values
  857.               KFS_OK
  858.                    The record was added successfully.
  859.          
  860.               KFS_Key_Already_Exists
  861.                    A record with the same key as the record being added 
  862.                    already exists in the database. The operation is 
  863.                    ignored.
  864.          
  865.               KFS_File_Error
  866.                    An unknown error occurred when attempting to add a 
  867.                    record to a KFS database.
  868.          
  869.               KFS_No_Space_On_Disk
  870.                    There was not enough space on the disk containing the 
  871.                    KFS file to contain another data and pointer record.
  872.          
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.                                 14
  887.  
  888.          
  889.          
  890.          
  891.          
  892.          
  893.  
  894.  
  895.  
  896.  
  897.  
  898.          KFS_Close(fs)
  899.               Close a database.
  900.          
  901.          
  902.          Parameters
  903.               KFS_FILEINFO *fs
  904.                    A pointer to a KFS file structure.
  905.          
  906.          
  907.          Description
  908.               Close a database. The database must then be opened before 
  909.               further processing can occur.
  910.          
  911.          
  912.          Required Fields
  913.               KFS_filename
  914.                    Contains the name of an opened database.
  915.          
  916.          
  917.          Example
  918.            /* Close a KFS file                                         */
  919.            #include <kfs.h>
  920.            KFS_FILEINFO file1;
  921.            .
  922.            .
  923.            KFS_Close(&file1);
  924.            
  925.          
  926.          Possible KFS_rc Values
  927.               KFS_OK
  928.                    The database was closed successfully.
  929.  
  930.  
  931.  
  932.  
  933.  
  934.  
  935.  
  936.  
  937.  
  938.  
  939.  
  940.  
  941.  
  942.  
  943.  
  944.  
  945.  
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.                                 15
  958.  
  959.          
  960.          
  961.          
  962.          
  963.          
  964.  
  965.  
  966.  
  967.  
  968.  
  969.          KFS_Create(fs)
  970.               Create a new, empty database and open it.
  971.          
  972.          Parameters
  973.               KFS_FILEINFO *fs
  974.                    A pointer to a KFS file structure.
  975.          
  976.          
  977.          Description
  978.               Create an empty database from the information supplied in 
  979.               the KFS_FILEINFO structure. At the conclusion of a suc-
  980.               cessful operation the database is opened and may be used 
  981.               without the need to call the KFS_Open function. If a data-
  982.               base already exists with this name, an error is returned.
  983.          
  984.          
  985.          Required Fields
  986.               KFS_keypos
  987.                    Contains the position of the key in the records of the 
  988.                    new database. This position is relative to 0.
  989.          
  990.               KFS_keylen
  991.                    Contains the length of the key. 
  992.          
  993.               KFS_recsize
  994.                    Contains the size of each of the keyed records to be 
  995.                    built.
  996.          
  997.               KFS_filename
  998.                    Contains the name of the database to be created. If 
  999.                    the name has a qualifier, it cannot be PTR. Also, the 
  1000.                    base portion of the name cannot be the same as any 
  1001.                    other database even if the qualifiers are unique.
  1002.          
  1003.               KFS_flags
  1004.                    Specifies some additional information about the data-
  1005.                    base (See the "Special Processing" section for more 
  1006.                    discussion of these options). The valid settings for 
  1007.                    this field are:
  1008.          
  1009.                         KFS_Normal_PTR
  1010.                              The normal pointer file organization is 
  1011.                              used. This results in the initial allocation 
  1012.                              of the .PTR file of about 8K but results in 
  1013.                              good performance for large databases.
  1014.          
  1015.                         KFS_Small_PTR
  1016.                              The organization of the pointer file will be 
  1017.                              changed to save space on the initial allo-
  1018.                              cation of the database. This option should 
  1019.                              be specified only when the database will be 
  1020.                              a small one since larger databases having 
  1021.                              this option are slower than for databases 
  1022.                              created with KFS_Normal_PTR.     
  1023.          
  1024.                         KFS_Numeric_Keys
  1025.                              The keys in the database will be numeric 
  1026.                              keys stored in the Intel long integer for-
  1027.                              mat. This option also implies a small 
  1028.                              pointer file. 
  1029.                                 16
  1030.  
  1031.          
  1032.          
  1033.          
  1034.          
  1035.          
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.          
  1042.                         KFS_Ignore_Case
  1043.                              The case of the keys in the database is 
  1044.                              ignored. That is, a key of "ABCDE" and "ab-
  1045.                              cde" will be treated as the same key.
  1046.          
  1047.          Example
  1048.            /* Create and open a KFS file with alphabetic keys starting */
  1049.            /* in the 5th position of the record and 7 bytes long       */ 
  1050.            #include <kfs.h>
  1051.            KFS_FILEINFO file1;
  1052.            char recarea[100];
  1053.          
  1054.            file1.KFS_flags = KFS_Normal_PTR;
  1055.            file1.KFS_keypos = 4;
  1056.            file1.KFS_keylen = 7;
  1057.            file1.KFS_recsize = 100;
  1058.            strcpy(file1.KFS_filename, "C:\\MYDIR\\MYFILE.DAT");
  1059.            KFS_Create(&file1);
  1060.            if (file1.KFS_rc != KFS_OK)
  1061.               printf("Error creating file1\n");
  1062.          
  1063.          
  1064.          Possible KFS_rc Values
  1065.               KFS_OK
  1066.                    The database was created successfully. 
  1067.          
  1068.               KFS_Keyed_File_Already_Exists
  1069.                    A database with this name already exists.
  1070.          
  1071.               KFS_Invalid_File_Name 
  1072.                    The file name and associated path name is longer than 
  1073.                    63 characters. 
  1074.          
  1075.               KFS_PTR_File_Open_Error
  1076.                    An unknown error occurred while attempting to open the 
  1077.                    PTR file associated with the database. This error can 
  1078.                    occur if there is not enough space on the disk to 
  1079.                    allocate the pointer file or if a .PTR file by this 
  1080.                    name already exists. 
  1081.          
  1082.               KFS_Data_File_Open_Error
  1083.                    An unknown error occurred while attempting to open the 
  1084.                    data file associated with the database.
  1085.          
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.                                 17
  1102.  
  1103.          
  1104.          
  1105.          
  1106.          
  1107.          
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.          KFS_Delete(fs, area)
  1114.               Delete a record from the database. 
  1115.          
  1116.          
  1117.          Parameters
  1118.               KFS_FILEINFO *fs
  1119.                    A pointer to a KFS file structure.
  1120.          
  1121.               void *area
  1122.                    A pointer to a data area containing the key of the 
  1123.                    record to be deleted. This key must be placed at 
  1124.                    KFS_keypos of this area before the operation is 
  1125.                    issued.
  1126.          
  1127.          Description
  1128.               Delete a record from the database.
  1129.          
  1130.          
  1131.          Required Fields
  1132.               KFS_filename
  1133.                    Contains the name of an opened database.
  1134.          
  1135.               area
  1136.                    The data area pointed to must contain the key of the 
  1137.                    record being deleted beginning in KFS_keypos of the 
  1138.                    area. 
  1139.          
  1140.          
  1141.          Example
  1142.            /* Add a record to a KFS file                              */
  1143.            #include <kfs.h>
  1144.            KFS_FILEINFO file1;
  1145.            typedef struct m {
  1146.               int f1;
  1147.               int f2;
  1148.               char mykey[7];
  1149.               char filler[89];
  1150.            } MYSTRUCT;
  1151.            MYSTRUCT inarea;
  1152.          
  1153.            strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
  1154.            KFS_Open(&file1);
  1155.            memset(&inarea.mykey, ' ', sizeof(inarea.mykey));
  1156.            strcpy(&inarea.mykey, "Dkey");
  1157.            KFS_Delete(&file1, (char *)&inarea);
  1158.            switch (file1.KFS_rc) {
  1159.               case KFS_OK:
  1160.                  break;
  1161.               case KFS_No_Space_On_Disk:
  1162.                  printf("Not enough space on disk to add record\n");
  1163.                  break;
  1164.               default:
  1165.                  printf("Error adding record\n");
  1166.          
  1167.            }
  1168.          
  1169.          Possible KFS_rc Values -
  1170.               KFS_OK
  1171.                    The record was deleted successfully.
  1172.          
  1173.                                 18
  1174.  
  1175.          
  1176.          
  1177.          
  1178.          
  1179.          
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.               KFS_Key_Not_Found
  1186.                    A record with the key specified was not found. The 
  1187.                    operation is ignored.
  1188.          
  1189.               KFS_No_Space_On_Disk
  1190.                    There is not enough space on the disk containing the 
  1191.                    KFS database to add a record.
  1192.          
  1193.  
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199.  
  1200.  
  1201.  
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.                                 19
  1246.  
  1247.          
  1248.          
  1249.          
  1250.          
  1251.          
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.          KFS_Open(fs)
  1258.               Open an existing database. 
  1259.          
  1260.          Parameters
  1261.               KFS_FILEINFO *fs
  1262.                    A pointer to a KFS file structure.
  1263.          
  1264.          
  1265.          Description
  1266.               Open an existing database for processing. All databases 
  1267.               must be opened before any processing may be done on those 
  1268.               databases. 
  1269.          
  1270.          
  1271.          Required Fields
  1272.               KFS_filename
  1273.                    Contains the name of an existing database to be 
  1274.                    opened.
  1275.          
  1276.          
  1277.          Example
  1278.            /* Open a KFS file                                          */
  1279.            #include <kfs.h>
  1280.            KFS_FILEINFO file1;
  1281.            char recarea[100];
  1282.          
  1283.            strcpy(file1.KFS_filename, "C:\\MYDIR\\MYFILE.DAT");
  1284.            KFS_Open(&file1);
  1285.            if (file1.KFS_rc != KFS_OK)
  1286.               printf("Error opening file1\n");
  1287.          
  1288.          
  1289.          Possible KFS_rc Values
  1290.               KFS_OK 
  1291.                    The database was opened successfully.
  1292.          
  1293.               KFS_Keyed_File_Does_Not_Exist 
  1294.                    The database does not exist.
  1295.          
  1296.               KFS_Invalid_File_Name
  1297.                    The database name and associated path name is longer 
  1298.                    than 63 characters. 
  1299.          
  1300.               KFS_PTR_File_Open_Error
  1301.                    An unknown error occurred while attempting to open the 
  1302.                    PTR file associated with the database. 
  1303.          
  1304.               KFS_Data_File_Open_Error
  1305.                    An unknown error occurred while attempting to open the 
  1306.                    data file associated with the database. 
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.                                 20
  1317.  
  1318.          
  1319.          
  1320.          
  1321.          
  1322.          
  1323.  
  1324.  
  1325.  
  1326.  
  1327.  
  1328.          KFS_Read(fs, area)
  1329.               Read a record by key from the database. 
  1330.          
  1331.          
  1332.          Parameters
  1333.               KFS_FILEINFO *fs
  1334.                    A pointer to a KFS file structure.
  1335.          
  1336.               void *area
  1337.                    A pointer to a data area where the requested record 
  1338.                    will be read. The key to be read must be placed at 
  1339.                    KFS_keypos of this area before the operation is 
  1340.                    issued.
  1341.          
  1342.          
  1343.          Description
  1344.               Read a record by key from a database.
  1345.          
  1346.          
  1347.          Required Fields
  1348.               KFS_filename
  1349.                    Contains the name of an open database.
  1350.          
  1351.               area
  1352.                    The data area pointed to must contain the key of the 
  1353.                    record being read beginning at position KFS_keypos. 
  1354.          
  1355.          
  1356.          Example
  1357.            /* Read a KFS file by key (keypos=4, keylen=7)              */
  1358.            #include <kfs.h>
  1359.            KFS_FILEINFO file1;
  1360.            char recarea[100];
  1361.          
  1362.            strcpy(file1.KFS_filename, "C:\\MYDIR\\MYFILE.DAT");
  1363.            KFS_Open(&file1);
  1364.            if (file1.KFS_rc != KFS_OK)
  1365.               printf("Error opening file1\n");
  1366.            memset(recarea, ' ', sizeof(recarea));
  1367.            /* Note - we kept the terminating NULL as part of the key   */
  1368.            strcpy(&recarea[file1.KFS_keypos], "A key");
  1369.            KFS_Read(&file1, (void *)recarea);
  1370.            if (file1.KFS_rc != KFS_OK)
  1371.               printf("Error reading keyed record from file1\n");
  1372.          
  1373.          
  1374.          Possible KFS_rc Values
  1375.               KFS_OK
  1376.                    The record was read successfully.
  1377.          
  1378.               KFS_Key_Not_Found
  1379.                    A record with the key specified was not found. The 
  1380.                    operation is ignored.
  1381.          
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.                                 21
  1389.  
  1390.          
  1391.          
  1392.          
  1393.          
  1394.          
  1395.  
  1396.  
  1397.  
  1398.  
  1399.  
  1400.          KFS_ReadFirst(fs, area)
  1401.               Read the first record in keyed sequence in the database. 
  1402.          
  1403.          
  1404.          Parameters
  1405.               KFS_FILEINFO *fs 
  1406.                    A pointer to a KFS file structure.
  1407.          
  1408.               void *area
  1409.                    A pointer to a data area where the first record in the 
  1410.                    KFS database will be read.
  1411.          
  1412.          
  1413.          Description
  1414.               Read the first record from a database. The record with the 
  1415.               lowest key will be read and placed in the data area. 
  1416.          
  1417.          
  1418.          Required Fields
  1419.               KFS_filename
  1420.                    Contains the name of an open database.
  1421.          
  1422.          
  1423.          Example
  1424.            /* Read the all of the records sequentially from a file    */
  1425.            #include <kfs.h>
  1426.            KFS_FILEINFO file1;
  1427.            char recarea[100];
  1428.            
  1429.            strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
  1430.            KFS_Open(&file1);
  1431.            if (file1.KFS_rc != KFS_OK)
  1432.               printf("Error opening file1\n");
  1433.            KFS_ReadFirst(&file1, recarea);
  1434.            if (file1.KFS_rc != KFS_OK) printf("Error");
  1435.          
  1436.          
  1437.          Possible KFS_rc Values -
  1438.               KFS_OK
  1439.                    The record was read successfully.
  1440.          
  1441.               KFS_Keyed_File_Empty
  1442.                    No records were found in the database. The operation 
  1443.                    is ignored.
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.                                 22
  1460.  
  1461.          
  1462.          
  1463.          
  1464.          
  1465.          
  1466.  
  1467.  
  1468.  
  1469.  
  1470.  
  1471.          KFS_ReadGen(fs, area, length)
  1472.               Read a record using a partial key. 
  1473.          
  1474.          Parameters
  1475.               KFS_FILEINFO *fs
  1476.                    A pointer to a KFS file structure.
  1477.          
  1478.               void *area
  1479.                    A pointer to a data area where the requested record 
  1480.                    will be read. The partial key to be used must be 
  1481.                    placed at KFS_keypos of this area before the operation 
  1482.                    is issued.
  1483.          
  1484.               int length
  1485.                    The length of the partial key at KFS_keypos. If the 
  1486.                    length specified is 0, the first record in the data-
  1487.                    base is read.This length must be less than or equal to 
  1488.                    KFS_keylen.
  1489.          
  1490.          Description
  1491.               Read the first record in the database whose first portion 
  1492.               matches that of the partial key supplied. If no record 
  1493.               matches the partial key, the next logical record in the 
  1494.               database is returned.
  1495.          
  1496.          
  1497.          Required Fields
  1498.               KFS_filename
  1499.                    Must contain the name of an open database.
  1500.          
  1501.               area
  1502.                    The data area pointed to must contain the key of the 
  1503.                    record being read. 
  1504.          
  1505.          
  1506.          Example
  1507.            /* Read a KFS file by partial key (keypos=4, keylen=7)     */
  1508.            #include <kfs.h>
  1509.            KFS_FILEINFO file1;
  1510.            char recarea[100];
  1511.          
  1512.            strcpy(file1.KFS_filename, "C:\\MYDIR\\MYFILE.DAT");
  1513.            KFS_Open(&file1);
  1514.            if (file1.KFS_rc != KFS_OK)
  1515.               printf("Error opening file1\n");
  1516.            strcpy(&recarea[file1.KFS_keypos], "A k");
  1517.            KFS_ReadGen(&file1, (void *)recarea, 3);
  1518.            if (file1.KFS_rc == KFS_Key_Not_Found)
  1519.               printf("We had no key match but got the next key\n");
  1520.            else
  1521.               if (file1.KFS_rc == KFS_OK)
  1522.                  printf("We got a record with a key starting with 'A 
  1523.          k'");
  1524.          
  1525.          Possible KFS_rc Values -
  1526.               KFS_OK
  1527.                    The partial key matched an existing record and this 
  1528.                    record was read successfully.
  1529.          
  1530.               KFS_Key_Not_Found
  1531.                                 23
  1532.  
  1533.          
  1534.          
  1535.          
  1536.          
  1537.          
  1538.  
  1539.  
  1540.  
  1541.  
  1542.  
  1543.                    No record with a key that matched the partial key 
  1544.                    specified was found. The next logical record in the 
  1545.                    database is returned.
  1546.          
  1547.               KFS_EOF
  1548.                    The partial key requested could not be found and the 
  1549.                    next position in the database was end of file.
  1550.          
  1551.               KFS_Key_Length_Invalid
  1552.                    A length greater than KFS_keylen was supplied in the 
  1553.                    parameter list.
  1554.          
  1555.               KFS_Invalid_Request
  1556.                    A KFS_ReadGen operation was attempted on a database 
  1557.                    with numeric keys.
  1558.          
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.  
  1592.  
  1593.  
  1594.  
  1595.  
  1596.  
  1597.  
  1598.  
  1599.  
  1600.  
  1601.  
  1602.  
  1603.                                 24
  1604.  
  1605.          
  1606.          
  1607.          
  1608.          
  1609.          
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.          KFS_ReadGenNumeric(fs, area)
  1616.               Read a numeric record, return the next record if not found. 
  1617.          
  1618.          
  1619.          Parameters -
  1620.               KFS_FILEINFO *fs 
  1621.                    A pointer to a KFS file structure.
  1622.          
  1623.               void *area
  1624.                    A pointer to a data area where the requested record 
  1625.                    will be read. A numeric key must be placed in 
  1626.                    KFS_keypos of this area prior to performing the 
  1627.                    operation.
  1628.           
  1629.          
  1630.          Description
  1631.               If a record in the database matches the key specified it is 
  1632.               read and placed in the data area. KFS_OK is then returned. 
  1633.               If no record matches the numeric key, then the next record 
  1634.               in the database is returned with a return code of 
  1635.               KFS_Key_Not_Found. 
  1636.          
  1637.          
  1638.          Required Fields
  1639.               KFS_filename
  1640.                    Contains the name of an open database.
  1641.          
  1642.               area
  1643.                    The data area pointed to must contain a numeric key at 
  1644.                    KFS_keypos. 
  1645.          
  1646.          
  1647.          Example
  1648.            /* Read a KFS file by numeric key (keypos=4)               */
  1649.            #include <kfs.h>
  1650.            KFS_FILEINFO file1;
  1651.            typedef struct m {
  1652.               int f1;
  1653.               int f2;
  1654.               long mykey;
  1655.               char filler[92];
  1656.            } MYSTRUCT;
  1657.            MYSTRUCT inarea;
  1658.          
  1659.            strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
  1660.            KFS_Open(&file1);
  1661.            if (file1.KFS_rc != KFS_OK)
  1662.               printf("Error opening file1\n");
  1663.            inarea.mykey = 1000;
  1664.            KFS_ReadGenNumeric(&file1, (void *)inarea);
  1665.            if (file1.KFS_rc == KFS_Key_Not_Found)
  1666.               printf("There was no key 1000 but got the next key\n");
  1667.          
  1668.            else
  1669.               if (file1.KFS_rc == KFS_OK)
  1670.                  printf("We got the record with key 1000");
  1671.          
  1672.          Possible KFS_rc Values
  1673.               KFS_OK
  1674.                    The record was read successfully.
  1675.                                 25
  1676.  
  1677.          
  1678.          
  1679.          
  1680.          
  1681.          
  1682.  
  1683.  
  1684.  
  1685.  
  1686.  
  1687.          
  1688.               KFS_Key_Not_Found
  1689.                    No record with a key that matched the key specified 
  1690.                    was found. The next logical record in the database is 
  1691.                    returned.
  1692.          
  1693.               KFS_EOF
  1694.                    The partial key requested could not be found and the 
  1695.                    next position in the database was at end of file.
  1696.  
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.  
  1724.  
  1725.  
  1726.  
  1727.  
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.  
  1735.  
  1736.  
  1737.  
  1738.  
  1739.  
  1740.  
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.                                 26
  1747.  
  1748.          
  1749.          
  1750.          
  1751.          
  1752.          
  1753.  
  1754.  
  1755.  
  1756.  
  1757.  
  1758.          KFS_ReadNext(fs, area)
  1759.               Read the next record in keyed sequence in the database. 
  1760.          
  1761.          
  1762.          Parameters
  1763.               KFS_FILEINFO *fs
  1764.                    A pointer to a KFS file structure.
  1765.          
  1766.               void *area
  1767.                    A pointer to a data area where the requested record 
  1768.                    will be read. The key placed at KFS_keypos of this 
  1769.                    area must be the key of the record before the record 
  1770.                    desired. 
  1771.          
  1772.          
  1773.          Description
  1774.               Read the next logical record from a database. The record 
  1775.               with the next highest key after the key specified in the 
  1776.               data area will be read. The user must provide the key of 
  1777.               the previous record in KFS_keypos of area. This allows the 
  1778.               user to read all records in a database with a succession of 
  1779.               KFS_ReadNext functions. 
  1780.          
  1781.          
  1782.          Required Fields
  1783.               KFS_filename
  1784.                    Contains the name of an open database.
  1785.          
  1786.               area
  1787.                    Contains the key of the record previous to the one to 
  1788.                    be read. 
  1789.           
  1790.          
  1791.          Example
  1792.            /* Read the all of the records sequentially from a file    */
  1793.            #include <kfs.h>
  1794.            KFS_FILEINFO file1;
  1795.            typedef struct m {
  1796.               int f1;
  1797.               int f2;
  1798.               char mykey[7];
  1799.               char filler[89];
  1800.            } MYSTRUCT;
  1801.            MYSTRUCT inarea;
  1802.          
  1803.            strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
  1804.            KFS_Open(&file1);
  1805.            if (file1.KFS_rc != KFS_OK)
  1806.               printf("Error opening file1\n");
  1807.              KFS_ReadFirst(&file1, (void *)&inarea);
  1808.            while (file1.KFS_rc != KFS_EOF) {
  1809.               KFS_ReadNext(&file1, (void *)&inarea);
  1810.          
  1811.               if (file1.KFS_rc != KFS_OK) printf("Error");
  1812.            }
  1813.            KFS_Close(&file1);
  1814.          
  1815.          Possible KFS_rc Values
  1816.               KFS_OK
  1817.                    The record was read successfully.
  1818.                                 27
  1819.  
  1820.          
  1821.          
  1822.          
  1823.          
  1824.          
  1825.  
  1826.  
  1827.  
  1828.  
  1829.  
  1830.          
  1831.               KFS_EOF
  1832.                    There are no more records in the dataset. 
  1833.          
  1834.               KFS_Key_Not_Found
  1835.                    A record with the specified key did not exist in the 
  1836.                    database and no record is returned. (i.e. the previous 
  1837.                    record must be found before the "next" record can be 
  1838.                    returned)
  1839.          
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.  
  1856.  
  1857.  
  1858.  
  1859.  
  1860.  
  1861.  
  1862.  
  1863.  
  1864.  
  1865.  
  1866.  
  1867.  
  1868.  
  1869.  
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.                                 28
  1891.  
  1892.          
  1893.          
  1894.          
  1895.          
  1896.          
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.          KFS_Replace(fs, area)
  1903.               Replace the record with the specified key.  
  1904.          
  1905.          
  1906.          Parameters
  1907.               KFS_FILEINFO *fs
  1908.                    A pointer to a KFS file structure.
  1909.          
  1910.               void *area
  1911.                    A pointer to a data area containing the record that 
  1912.                    will replace the record with the specified key in the 
  1913.                    database. 
  1914.          
  1915.          
  1916.          Description
  1917.               Replace the record with the corresponding key in the data-
  1918.               base with the record in area. If the record does not exist 
  1919.               in the database, the operation is ignored and a 
  1920.               KFS_Key_Not_found is returned. No prior read of the record 
  1921.               being replaced must be done. 
  1922.          
  1923.          
  1924.          Required Fields
  1925.               KFS_filename
  1926.                    Contains the name of an open database.
  1927.          
  1928.               area
  1929.                    Contains the record that will replace the one in the 
  1930.                    database.
  1931.           
  1932.          
  1933.          Example
  1934.            /* Replace a record in a KFS file                          */
  1935.            #include <kfs.h>
  1936.            KFS_FILEINFO file1;
  1937.            typedef struct m {
  1938.               int f1;
  1939.               int f2;
  1940.               char mykey[7];
  1941.               char filler[89];
  1942.            } MYSTRUCT;
  1943.            MYSTRUCT inarea;
  1944.          
  1945.            strcpy(file1.KFS_filename, "C:\\MYDIR\\NUMFILE.DAT");
  1946.            KFS_Open(&file1);
  1947.            strcpy(&inarea.mykey, "Oldkey");
  1948.            /* Note - we would not have to read to replace             */
  1949.            KFS_Read(&file1, (void *)&inarea);
  1950.            inarea.f2 = 77;
  1951.            KFS_Replace(&file1, (void *)&inarea);
  1952.            switch (file1.KFS_rc) {
  1953.               case KFS_Key_Not_Found :
  1954.          
  1955.                  printf("Record was not in file");
  1956.               case KFS_OK:
  1957.                  break;
  1958.               default:
  1959.                  printf("Error replacing record");
  1960.            }
  1961.          
  1962.                                 29
  1963.  
  1964.          
  1965.          
  1966.          
  1967.          
  1968.          
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.          Possible KFS_rc Values -
  1975.               KFS_OK
  1976.                    The record was read successfully.
  1977.          
  1978.               KFS_Key_Not_Found
  1979.                    A record with the key specified was not found. The 
  1980.                    operation is ignored.
  1981.          
  1982.               KFS_File_Error
  1983.                    An unknown error occurred when attempting to replace 
  1984.                    the requested record.
  1985.          
  1986.  
  1987.  
  1988.  
  1989.  
  1990.  
  1991.  
  1992.  
  1993.  
  1994.  
  1995.  
  1996.  
  1997.  
  1998.  
  1999.  
  2000.  
  2001.  
  2002.  
  2003.  
  2004.  
  2005.  
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012.  
  2013.  
  2014.  
  2015.  
  2016.  
  2017.  
  2018.  
  2019.  
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030.  
  2031.  
  2032.  
  2033.  
  2034.                                 30
  2035.  
  2036.          
  2037.          
  2038.          
  2039.          
  2040.          
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.          Interdependencies of the KFS operations
  2047.          
  2048.          Except for the requirements for opening databases first and 
  2049.          closing databases last, there is no specific dependencies 
  2050.          between KFS operations. That is, there is no requirement to call 
  2051.          a specific function before another function can be called. For 
  2052.          example, it is not necessary to read a specific record before 
  2053.          replacing it with KFS_Replace. The same is true if you want to 
  2054.          delete a record, it is not necessary to read it first. Simi-
  2055.          larly, you can issue a KFS_ReadNext after any other operation, 
  2056.          as long as the key of an existing record is present in the data 
  2057.          area so that KFS_ReadNext can read the record with the next 
  2058.          highest key.
  2059.          
  2060.  
  2061.  
  2062.  
  2063.  
  2064.  
  2065.  
  2066.  
  2067.  
  2068.  
  2069.  
  2070.  
  2071.  
  2072.  
  2073.  
  2074.  
  2075.  
  2076.  
  2077.  
  2078.  
  2079.  
  2080.  
  2081.  
  2082.  
  2083.  
  2084.  
  2085.  
  2086.  
  2087.  
  2088.  
  2089.  
  2090.  
  2091.  
  2092.  
  2093.  
  2094.  
  2095.  
  2096.  
  2097.  
  2098.  
  2099.  
  2100.  
  2101.  
  2102.  
  2103.  
  2104.  
  2105.  
  2106.                                 31
  2107.  
  2108.          
  2109.          
  2110.          
  2111.          
  2112.          
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118.          Special Processing
  2119.          
  2120.          There are a few special options that may be chosen when creating 
  2121.          a database with the Keyed File System that allow for special 
  2122.          uses of databases. These options are enabled by setting certain 
  2123.          bits in the KFS_flags field of the File Information Structure. 
  2124.          If none of the options are desired, the flags field should be 
  2125.          set to KFS_Normal_PTR. Normally, databases are relatively large 
  2126.          databases (such as customer record databases) with keys that 
  2127.          contain primarily letters (people's names, for example) and the 
  2128.          Keyed File System was designed to handle these databases most 
  2129.          efficiently. Some assumptions are made about the number and type 
  2130.          of keys that will exist in the database when it is created and 
  2131.          results in creating an initial .PTR file of about 8K bytes. 
  2132.          Because of this initial allocation, the .PTR file is normally 
  2133.          slow to grow. However, for some applications, the assumptions 
  2134.          made by the Keyed File System may not be correct. Three options 
  2135.          are provided to enable the programmer to select a more efficient 
  2136.          initial .PTR allocation or to utilize various types of keys. 
  2137.          
  2138.          
  2139.          KFS_Small_PTR
  2140.           
  2141.          For applications that need relatively small databases (up to a 
  2142.          few hundred records), the KFS_Small_PTR option provides a way to 
  2143.          greatly reduce the initial size of the .PTR file from 8K to a 
  2144.          few hundred bytes. However, using this option will result in 
  2145.          slower execution speed if the database does grow large. Note 
  2146.          that this does not prohibit the database from becoming large, 
  2147.          just that performance is slower should it do so.
  2148.          
  2149.          The option is enabled by setting the KFS_flags field to 
  2150.          KFS_Small_PTR. In C this could be done by the following code :
  2151.          
  2152.            #include <kfs.h>
  2153.            KFS_FILEINFO file1;
  2154.            file1.KFS_flags = KFS_Small_PTR;
  2155.          
  2156.          
  2157.          KFS_Numeric_Key
  2158.          
  2159.          For applications whose keys are all numbers, it would be more 
  2160.          efficient of these numbers could be stored in the normal way 
  2161.          that the Intel 80x86 stores numbers. That is, in byte reversed 
  2162.          binary form (ie. short, int, or long in C terminology). The 
  2163.          Keyed File System provides the KFS_Numeric_Key option that 
  2164.          allows the key to be stored in the 4 byte Intel integer format 
  2165.          (ie. C's "long int"). Using this option will cause the system to 
  2166.          assume that KFS_keypos indicates the beginning of a 4 byte key 
  2167.          that is a number stored in integer form. KFS_keylen is ignored 
  2168.          when this option is specified. 
  2169.            
  2170.          
  2171.          The option is enabled by setting the KFS_flags field to 
  2172.          KFS_Numeric_Key. In C this could be done by the following code :
  2173.          
  2174.            #include <kfs.h>
  2175.            KFS_FILEINFO file1;
  2176.            file1.KFS_flags = KFS_Numeric_Key;
  2177.          
  2178.                                 32
  2179.  
  2180.          
  2181.          
  2182.          
  2183.          
  2184.          
  2185.  
  2186.  
  2187.  
  2188.  
  2189.  
  2190.          
  2191.          KFS_Ignore_Case
  2192.          
  2193.          Normally, databases created with alphabetic keys are sensitive 
  2194.          to the case of the keys. That is, keys "ABCDE" and "abcde" 
  2195.          indicate the keys of two different records. However, setting 
  2196.          this option allows case to be ignored for databases that have 
  2197.          alphabetic keys. Then a database created with this option would 
  2198.          treat the keys "ABCDE" and "abcde" as the key to the same 
  2199.          record.
  2200.          
  2201.          The option can be combined with the KFS_Normal_PTR or 
  2202.          KFS_Small_PTR options and is enabled by setting the KFS_flags 
  2203.          field to KFS_Ignore_Case. In C this could be done by the fol-
  2204.          lowing code :
  2205.          
  2206.            #include <kfs.h>
  2207.            KFS_FILEINFO file1;
  2208.            file1.KFS_flags = KFS_Normal_PTR | KFS_Ignore_Case;
  2209.  
  2210.  
  2211.  
  2212.  
  2213.  
  2214.  
  2215.  
  2216.  
  2217.  
  2218.  
  2219.  
  2220.  
  2221.  
  2222.  
  2223.  
  2224.  
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  
  2249.                                 33
  2250.  
  2251.          
  2252.          
  2253.          
  2254.          
  2255.          
  2256.  
  2257.  
  2258.  
  2259.  
  2260.  
  2261.          Programming Hints and Tips
  2262.          
  2263.          In this section we will try to provide some hints, examples, 
  2264.          and, hopefully, the answers to some questions to help an appli-
  2265.          cation developer in using the Keyed File System. As part of the 
  2266.          KFS package we have included the source to the sample and util-
  2267.          ity programs we have provided. These programs will provide some 
  2268.          concrete coding examples of how to use the functions we have 
  2269.          described. Use them to reinforce some of the examples we use in 
  2270.          this section.  
  2271.          
  2272.          *    Ensure that when creating a database that the KFS_flags 
  2273.               field is properly set to one of the valid options.
  2274.          
  2275.          *    When specifying a key in the data area for an operation 
  2276.               that requires a key, make sure that all bytes in the key 
  2277.               field are set to a known value. Remember, the Keyed File 
  2278.               System always assumes the key is KFS_keylen bytes long, 
  2279.               irrespective of any NULLS in the key field. A common mis-
  2280.               take is not to "clear" the key field before moving in a key 
  2281.               that may be shorter than keylen. For example, STRCPY only 
  2282.               moves data until a '00'X is detected in the source. Thus, 
  2283.               if what is being moved in is shorter than KFS_keylen, the 
  2284.               remaining bytes of the key field will remain unchanged (ie. 
  2285.               may contain garbage). Additionally, consider that STRCPY 
  2286.               also moves the terminating NULL character and that will 
  2287.               become part of the key. This may be OK, just realize that 
  2288.               the NULL is there. A good habit to get into when using KFS 
  2289.               functions is illustrated by the following code:
  2290.          
  2291.               #include <kfs.h>
  2292.               KFS_FILEINFO file1;
  2293.               char area[80];
  2294.               memset(&area[file1.KFS_keypos], ' ', file1.KFS_keylen);
  2295.               strcpy(&area[file1.KFS_keypos, newkey);
  2296.          
  2297.               This code sequence initially sets the key field of "area" 
  2298.               to blanks and then copies in the desired key from the 
  2299.               "newkey" variable. 
  2300.          
  2301.          *    You will notice that the Keyed File System does not allow 
  2302.               for duplicate keys. However, with a little thought, the 
  2303.               KFS_ReadGen and KFS_ReadNext functions can be used to pro-
  2304.               vide a similar capability. For example, if you wanted to 
  2305.               have a database whose key was a name field, duplicate names 
  2306.               could be avoided by making the key field the name AND 
  2307.               account number. You could still issue a KFS_ReadGen for 
  2308.               only the name and then use KFS_ReadNext to read the rest of 
  2309.               the records having the same name. 
  2310.          
  2311.          *    If KFS_ReadNext tries to read the next record after the 
  2312.               last logical record in the database (ie. the record with 
  2313.               the highest key) a KFS_EOF is returned. If another 
  2314.               KFS_ReadNext is issued, KFS_EOF will again be returned. 
  2315.               However, other operations (such as KFS_Read) are still 
  2316.               allowed on the database and will result in KFS_rc to be set 
  2317.               to another value (such as KFS_OK if the read is success-
  2318.               ful). Further KFS_ReadNext operations may be performed from 
  2319.               that spot in the database.
  2320.          
  2321.                                 34
  2322.  
  2323.          
  2324.          
  2325.          
  2326.          
  2327.          
  2328.  
  2329.  
  2330.  
  2331.  
  2332.  
  2333.          *    We mentioned earlier that numeric and alphabetic keys can-
  2334.               not be combined. However, if you keep in mind that shorts 
  2335.               and longs are stored in byte reversed format, you can form 
  2336.               keys that mix data types. The following code segment com-
  2337.               bines an alphabetic customer name and a numeric (i.e. long) 
  2338.               customer number into a single key. The customers names 
  2339.               would be in the database in alphabetic sequence, but cus-
  2340.               tomers with the same name would not necessarily be in 
  2341.               sequence by customer number (customer number 256, stored as 
  2342.               '00010000'x, would be before customer number 255, stored as 
  2343.               'FF000000'x, for example). 
  2344.          
  2345.                    #include <kfs.h>
  2346.                    struct DA {
  2347.                         char custname[40];
  2348.                         long custnum;
  2349.                         char morestuff[40];
  2350.                    } myarea;
  2351.                    KFS_FILEINFO myfile; 
  2352.                       :
  2353.                    myfile.KFS_keypos = 0;
  2354.                    myfile.KFS_keylen = 44;
  2355.                       :
  2356.                    KFS_Create(&myfile);          
  2357.  
  2358.  
  2359.  
  2360.  
  2361.  
  2362.  
  2363.  
  2364.  
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.  
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.  
  2381.  
  2382.  
  2383.  
  2384.  
  2385.  
  2386.  
  2387.  
  2388.  
  2389.  
  2390.  
  2391.  
  2392.                                 35
  2393.  
  2394.          
  2395.          
  2396.          
  2397.          
  2398.          
  2399.  
  2400.  
  2401.  
  2402.  
  2403.  
  2404.          Data Recovery
  2405.          
  2406.          Most programmers are familiar with damaged data files caused by 
  2407.          unusual system problems (power failures or system crashes) while 
  2408.          a file is being written to disk. While these problems are rare, 
  2409.          they do occur. The Keyed File System contains code that attempts 
  2410.          to minimize the impact of such a system failure, but this impact 
  2411.          cannot be eliminated completely. Since the Keyed File System 
  2412.          uses two related DOS files (an index file and a data file) to 
  2413.          manage a database, damage to one of these files can cause the 
  2414.          database to become unusable. With a little planning, however, a 
  2415.          programmer can frequently recover a damaged KFS database with 
  2416.          little or no loss of data. To do this requires a little knowl-
  2417.          edge of the internals of KFS. 
  2418.          
  2419.          The data file that makes up a KFS database is a normal DOS 
  2420.          binary file. That is, each "logical" record is KFS_recsize bytes 
  2421.          long and does not contain a CR/LF at the end of each record. 
  2422.          Thus, these records can be read using operating system or C 
  2423.          language functions just like any other binary file. Addition-
  2424.          ally, when KFS deletes a record, it is not physically removed 
  2425.          from the data file but only from the .PTR file. However, it is 
  2426.          marked for reuse and a hex 'FF' is placed in the last byte of 
  2427.          the data record when a record is deleted. This hex 'FF' has no 
  2428.          consequence to KFS since deleted records are tracked another way 
  2429.          internally, but can be useful for a programmer wanting to 
  2430.          recover a damaged KFS database by using only the data file. If, 
  2431.          when writing an application, a programmer using the Keyed File 
  2432.          System ensures that the last byte of each data record cannot 
  2433.          normally be hex 'FF', then recovering a KFS database can be 
  2434.          relatively simple. A database recovery program can be written 
  2435.          that simply reads the data portion of the damaged KFS database 
  2436.          as fixed length binary records, checks to ensure the last byte 
  2437.          of each record is not hex 'FF' (remember, hex 'FF' means the 
  2438.          record has been deleted), and uses the KFS_Add operation to add 
  2439.          the record to a new KFS database. At the conclusion of such a 
  2440.          recovery program, the new KFS database would contain all of the 
  2441.          undamaged records that existed in the original KFS database. A 
  2442.          simple example of this technique appears in Appendix B.
  2443.          
  2444.  
  2445.  
  2446.  
  2447.  
  2448.  
  2449.  
  2450.  
  2451.  
  2452.  
  2453.  
  2454.  
  2455.  
  2456.  
  2457.  
  2458.  
  2459.  
  2460.  
  2461.  
  2462.  
  2463.  
  2464.                                 36
  2465.  
  2466.          
  2467.          
  2468.          
  2469.          
  2470.          
  2471.  
  2472.  
  2473.  
  2474.  
  2475.  
  2476.          Appendix A - Keyed File System Return Codes
  2477.          
  2478.          The following is a list of return codes generated by the Keyed 
  2479.          File System. These definitions are found in the supplied header 
  2480.          file (KFS.H). 
  2481.          
  2482.          KFS_OK (0)
  2483.               The operation completed successfully. 
  2484.          
  2485.          KFS_Data_File_Open_Error (3)
  2486.               A bad return code was return from the system when trying to 
  2487.               open the data file of the database.
  2488.          
  2489.          KFS_EOF (-1)
  2490.               End of file was reached on the data database during a 
  2491.               KFS_ReadNext. The database remains open and subsequent 
  2492.               keyed operations are allowed.
  2493.          
  2494.          KFS_File_Error (8)
  2495.               An unknown error was returned by the operating system.
  2496.          
  2497.          KFS_File_Already_Exists (9)
  2498.               You are trying to create a database that already exists in 
  2499.               this directory.
  2500.          
  2501.          KFS_Invalid_File_Name (1) 
  2502.               The database name requested in KFS_filename is longer than 
  2503.               the 63 characters allowed by the Keyed File System. 
  2504.          
  2505.          KFS_Invalid_Request (11)
  2506.               You are attempting to do a KFS_ReadGen on a database with 
  2507.               numeric keys. Use a KFS_ReadGenNumeric function instead.
  2508.          
  2509.          KFS_Key_Already_Exists (4)
  2510.               A record with the key specified already exists in the 
  2511.               database.
  2512.          
  2513.          KFS_Key_Length_Invalid (12)
  2514.               The length of the partial key specified for a KFS_ReadGen 
  2515.               was either 0 or greater than the key length for this data-
  2516.               base.
  2517.          
  2518.          KFS_Key_Not_Found (5)
  2519.               A record with the key specified does not exist in the 
  2520.               database.
  2521.          
  2522.          KFS_Keyed_File_Empty (7)
  2523.               When attempting to execute a KFS_ReadFirst operation it was 
  2524.               discovered that the database had no records. 
  2525.          
  2526.          
  2527.          
  2528.          
  2529.               KFS_No_Space_On_Disk (13)
  2530.               There is no space on the disk containing the KFS database 
  2531.               to add a new record.
  2532.          
  2533.          KFS_Prior_Key_Not_Found (6)
  2534.               The key specified as the prior key in a KFS_ReadNext was 
  2535.               not found in the database.
  2536.                                 37
  2537.  
  2538.          
  2539.          
  2540.          
  2541.          
  2542.          
  2543.  
  2544.  
  2545.  
  2546.  
  2547.  
  2548.          
  2549.          KFS_PTR_File_Open_Error (2)
  2550.               A bad return code was return from the system when trying to 
  2551.               open the pointer file of the database. 
  2552.          
  2553.          KFS_Recordsize_Too_Short (10)
  2554.               The amount specified in KFS_recsize is smaller than 
  2555.               KFS_keypos + KFS_keylen.
  2556.  
  2557.  
  2558.  
  2559.  
  2560.  
  2561.  
  2562.  
  2563.  
  2564.  
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.  
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.  
  2579.  
  2580.  
  2581.  
  2582.  
  2583.  
  2584.  
  2585.  
  2586.  
  2587.  
  2588.  
  2589.  
  2590.  
  2591.  
  2592.  
  2593.  
  2594.  
  2595.  
  2596.  
  2597.  
  2598.  
  2599.  
  2600.  
  2601.  
  2602.  
  2603.  
  2604.  
  2605.  
  2606.  
  2607.                                 38
  2608.  
  2609.          
  2610.          
  2611.          
  2612.          
  2613.          
  2614.  
  2615.  
  2616.  
  2617.  
  2618.  
  2619.          Appendix B - File Recovery Example
  2620.          
  2621.          The following is an example of a C program that could be used to 
  2622.          recover a KFS database. Assume the damaged database had the 
  2623.          following characteristics:
  2624.          
  2625.               KFS_filename   = C:\DATA\MYFILE.DAT
  2626.               KFS_recsize    = 100
  2627.               KFS_keypos     = 0
  2628.               KFS_keylen     = 15
  2629.          
  2630.          The C program to recover this database could look like this:
  2631.          
  2632.          main()
  2633.          {
  2634.             /* Example of how to recover a KFS file if .PTR is damaged */
  2635.             FILE *old;
  2636.             KFS_FILEINFO new;
  2637.             char dataarea[100];
  2638.          
  2639.             old = fopen("C:\\DATA\\MYFILE.DAT", "rb");
  2640.             new.KFS_recsize = 100;
  2641.             new.KFS_keylen = 15;
  2642.             new.KFS_keypos = 0;
  2643.             new.KFS_flags = KFS_Normal_PTR;
  2644.             strcpy(new.KFS_filename, "C:\\WORK\\MYFILE.DAT");
  2645.             KFS_Create(&new);
  2646.             fread(&dataarea, sizeof(dataarea), 1, old);
  2647.             while(!feof(old))
  2648.             {
  2649.                if (dataarea[new.KFS_recsize - 1] != 0xff)
  2650.                   KFS_Add(&new, &dataarea);
  2651.                fread(&dataarea, sizeof(dataarea), 1, old);
  2652.             }
  2653.             fclose(old);
  2654.             KFS_Close(&new);
  2655.          }
  2656.  
  2657.  
  2658.  
  2659.  
  2660.  
  2661.  
  2662.  
  2663.  
  2664.  
  2665.  
  2666.  
  2667.  
  2668.  
  2669.  
  2670.  
  2671.  
  2672.  
  2673.  
  2674.  
  2675.  
  2676.  
  2677.  
  2678.                                 39
  2679.  
  2680.          
  2681.          
  2682.          
  2683.